define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'jdgoods/index',
                    add_url: 'jdgoods/add',
                    edit_url: 'jdgoods/edit',
                    del_url: 'jdgoods/del',
                    multi_url: 'jdgoods/multi',
                    table: 'jd_goods',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'materialId', title: __('Materialid')},
                        {field: 'promotionType', title: __('Promotiontype')},
                        {field: 'pcDetails', title: __('Pcdetails')},
                        {field: 'mDetails', title: __('Mdetails')},
                        {field: 'logTitle', title: __('Logtitle')},
                        {field: 'imgUrl', title: __('Imgurl'), formatter: Table.api.formatter.url},
                        {field: 'logUnitPrice', title: __('Logunitprice')},
                        {field: 'PopId', title: __('Popid')},
                        {field: 'couponLink', title: __('Couponlink')},
                        {field: 'orienPlanId', title: __('Orienplanid')},
                        {field: 'adOwner', title: __('Adowner')},
                        {field: 'pcComm', title: __('Pccomm')},
                        {field: 'wlComm', title: __('Wlcomm')},
                        {field: 'logCategory', title: __('Logcategory')},
                        {field: 'logSaler', title: __('Logsaler')},
                        {field: 'planId', title: __('Planid')},
                        {field: 'couponAmount', title: __('Couponamount')},
                        {field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'update_time', title: __('Update_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'is_recommend', title: __('Is_recommend')},
                        {field: 'commission', title: __('Commission'), operate:'BETWEEN'},
                        {field: 'longCouponUrl', title: __('Longcouponurl'), formatter: Table.api.formatter.url},
                        {field: 'longUrl', title: __('Longurl'), formatter: Table.api.formatter.url},
                        {field: 'qRcode', title: __('Qrcode')},
                        {field: 'shotCouponUrl', title: __('Shotcouponurl'), formatter: Table.api.formatter.url},
                        {field: 'shotUrl', title: __('Shoturl'), formatter: Table.api.formatter.url},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});